package com.jcoinexchage.user.controller.web;

import com.jcoinexchage.user.business.MemberLoginService;
import com.jcoinexchage.user.common.vo.LoginPwdReq;
import com.jcoinexchage.user.common.vo.LoginTokenRes;
import com.jcoinexchange.web.auth.ErrorCode;
import com.jcoinexchange.web.entity.BasicResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "授权")
@RestController
@RequestMapping("/login")
public class LoginController {

    @Resource
    private MemberLoginService memberLoginService;

    @Operation(summary = "密码登录")
    @PostMapping("/byPwd")
    public BasicResponse<LoginTokenRes> byPwd(@RequestBody @Valid LoginPwdReq req) {
        try{
            return BasicResponse.success(memberLoginService.loginByAccountPwd(req));
        }catch (Exception e){
            // TODO: 2025/2/20 SYSTEM_ERROR code
            return BasicResponse.error(ErrorCode.ERROR_NOT_AUTHED);
        }
    }
}
